﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using Caliburn.Core.InversionOfControl;
using Caliburn.PresentationFramework.Filters;
using Caliburn.PresentationFramework.RoutedMessaging;
using Caliburn.PresentationFramework.Screens;
using Caliburn.ShellFramework.Results;
using MTGenome.MTG;

namespace MTGenome.ViewModels
{
    [Singleton(typeof(MainWindowViewModel)), PartCreationPolicy(CreationPolicy.Shared)]
    public sealed class MainWindowViewModel : Conductor<IScreen>
    {
        private readonly IGathererServer _gatherer;

        public MainWindowViewModel(IGathererServer gatherer)
        {
            _gatherer = gatherer;

            DisplayName = "MTGenome";
            _gatherer.OfflineChanged += (sender, e) => NotifyOfPropertyChange(() => Offline);
        }

        public void Open<T>() where T : IScreen
        {
            ActivateItem(IoC.Get<T>());
        }

        protected override void OnActivate()
        {
            base.OnActivate();

            Open<HomeViewModel>();
        }
       
        public bool CanGoHome
        {
            get { return !(ActiveItem is HomeViewModel); }
        }

        [Dependencies("ActiveItem")]
        public void GoHome()
        {
            Open<HomeViewModel>();
        }

        public bool Offline
        {
            get { return _gatherer.Offline; }
            set { _gatherer.Offline = value; }
        }

        public IResult ShowAbout()
        {
            return Show.Dialog<AboutViewModel>();
        }
    }
}
